# encoding: utf-8
# @File  : set_allure_environment.py
# @Author: wu shaofan
# @Date  :  2024/04/17
# @Desc : 设置allure报告中的环境信息
import os
import sys
import xml.etree.ElementTree as ET


def set_report_xml_on_results(path):
    # 创建一个根元素
    root = ET.Element("environment")

    # 创建子元素并添加数据
    parameters = [
        {"key": "项目名称", "value": "TPshop商城"},
        {"key": "运行环境", "value": sys.platform},
        {"key": "测试账号/密码", "value": "18325530001/wsf123456"},
        {"key": "项目地址", "value": "https://hmshop-test.itheima.net/index.php"},
        {"key": "Chrome浏览器版本", "value": "124.0.6367.61（正式版本）"},
        {"key": "测试人员", "value": "吴彦祖"},
    ]
    for param in parameters:
        parameter = ET.SubElement(root, "parameter")
        ET.SubElement(parameter, "key").text = param["key"]
        ET.SubElement(parameter, "value").text = param["value"]

    # 生成XML树对象
    tree = ET.ElementTree(root)

    # 创建XML文档并写入文件
    allure_xml_file = os.path.join(path, 'environment.xml')
    tree.write(allure_xml_file, encoding="utf-8", xml_declaration=True)
